package com.example.my.agiftthat.helper;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import java.util.List;

/**
 * Created by StevenWang on 16/8/2.
 */
public abstract class RecyclerViewAdapterHelper<T> extends RecyclerView.Adapter<RecyclerView
        .ViewHolder> {
    public Context context = null;
    public List<T> list = null;
    public LayoutInflater inflater = null;

    public RecyclerViewAdapterHelper(Context context, List<T> list) {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return onCreateMyViewHolder(parent, viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        onBindMyViewHolder(holder, position);
    }

    public abstract RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType);

    public abstract void onBindMyViewHolder(RecyclerView.ViewHolder holder, int position);


    @Override
    public int getItemCount() {
        return list.size();
    }

    public void reloadRecyclerView(List<T> _list, boolean isClear) {
        if (isClear) {
            list.clear();
        }
        list.addAll(_list);
        notifyDataSetChanged();
    }
}
